package org.springblade.modules.admin.entity.excel;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.modules.admin.enums.MaintainPlanContentEnum;
import org.springblade.modules.admin.enums.TaskStatusEnum;
import org.springblade.modules.admin.vo.plan.PlanSignStatusVo;
import org.springblade.modules.admin.vo.plan.PlanUserSignDetailVo;
import org.springblade.modules.admin.vo.plan.SignStatusInfoVo;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 预留保养工单ExcelModule
 * @author: Sharry
 * @createTime: 2023/3/15 18:30
 * @version: Version-1.0
 */
@Data
public class UserLeaveMaintainExcel implements Serializable {

	private Long planId;

	private String userSignInfos;

	private String userSignInfos2;

	List<SignStatusInfoVo> userSignInfoList;

	List<PlanUserSignDetailVo> userSignInfoList2;

	@ApiModelProperty("实际执行人")
	List<PlanUserSignDetailVo> realUserSignInfoList;

	private String groupName;

	private String buildingName;

	private String elevatorNo;

	private String planDesc;

	private String planDate;

	private String planStartTime;

	private String planEndTime;

	private Integer planStatus;

	private String planStatusName;

	private Integer overdueDay;

	private String overdueDayName;

	private String planCheckName;

	@ApiModelProperty("工作时长")
	private Integer workMinute;

	@ApiModelProperty("评分状态 0-未评分，1-已评分")
	private Integer scoreStatus;

	@ApiModelProperty("评分分数")
	private BigDecimal score;

	@ApiModelProperty("工作时长")
	private String workMinuteName;

	private String imageNums;

	private Integer imageCounts = 0;

	private Date createTime;

	private String mfDesc;

	private String realNames;

	private Integer isStop;

	private Integer deferType;
	private String deferTypeName;

	private Integer deferWarrant;

	private String deferWarrantName;

	@ApiModelProperty("延期总次数")
	private Integer deferCounts;

	@ApiModelProperty("延期文案总次数")
	private Integer deferDescCounts;

	private Integer auditType;

	public void setDeferType(Integer deferType) {
		deferType = Convert.toInt(deferType, 4);
		this.deferType = deferType;
		if (deferType == 1) {
			this.deferTypeName = "已延期";
		} else if (deferType == 2) {
			this.deferTypeName = "已提前";
		} else if (deferType == 3) {
			this.deferTypeName = "无变化";
		} else if (deferType == 4) {
			this.deferTypeName = "从未调整";
		} else if (deferType == 5) {
			this.deferTypeName = "特殊延期";
		}
	}

	public void setDeferWarrant(Integer deferWarrant) {
		deferWarrant = Convert.toInt(deferWarrant, 4);
		this.deferWarrant = deferWarrant;
		if (deferWarrant == 1) {
			this.deferWarrantName = "未提交";
		} else if (deferWarrant == 2) {
			this.deferWarrantName = "已齐全";
		} else if (deferWarrant == 3) {
			this.deferWarrantName = "未完善";
		} else if (deferWarrant == 4) {
			this.deferWarrantName = "无需提交";
		} else if (deferWarrant == 5) {
			this.deferWarrantName = "未提交";
		}
	}

	private List<PlanSignStatusVo> planSignStatusList;

	public void setUserSignInfos2(String userSignInfos2) {
		this.userSignInfos2 = userSignInfos2;
		List<PlanUserSignDetailVo> list = new ArrayList<>();
		List<PlanUserSignDetailVo> list2 = new ArrayList<>();

		if (StrUtil.isNotEmpty(userSignInfos2)) {
			String[] split = userSignInfos2.split("%");
			for (String str : split) {
				PlanUserSignDetailVo planUserSignDetailVo = JSON.parseObject(str, PlanUserSignDetailVo.class);
				list.add(planUserSignDetailVo);
				if (planUserSignDetailVo.getIsTakePartIn()) {
					list2.add(planUserSignDetailVo);
				}
			}
		}
		if (list.size() > 0) {
			this.userSignInfoList2 = list;
		}
		if (list2.size() > 0) {
			this.realUserSignInfoList = list2;
		}
	}

	public void setImageNums(String imageNums) {
		int imageCount = 0;
		this.imageNums = imageNums;
		if (StrUtil.isNotEmpty(imageNums)) {
			String[] split = imageNums.split("%");
			for (String str : split) {
				imageCount = imageCount + Convert.toInt(str, 0);
			}
			this.imageCounts = imageCount;
		}
	}

	public void setOverdueDay(Integer overdueDay) {
		this.overdueDay = Convert.toInt(overdueDay, 0);
		if (overdueDay > 0) {
			this.overdueDayName = "已逾期";
		} else {
			this.overdueDayName = "及时";
		}
	}

	public void setPlanStatus(Integer planStatus) {
		this.planStatus = planStatus;
		this.planStatusName = TaskStatusEnum.getTaskName(MaintainPlanContentEnum.MAINTAIN_BY.getId(), planStatus);
	}

	public void setUserSignInfos(String userSignInfos) {
		if (StrUtil.isNotEmpty(userSignInfos)) {
			List<SignStatusInfoVo> list = new ArrayList<>();
			String[] split = userSignInfos.split("%");
			for (String str : split) {
				SignStatusInfoVo signStatusInfoVo = JSON.parseObject(str, SignStatusInfoVo.class);
				list.add(signStatusInfoVo);
			}
			this.userSignInfoList = list;
		}
		this.userSignInfos = userSignInfos;

	}


	public void setWorkMinute(Integer workMinute) {
		this.workMinute = workMinute;
		if (workMinute != null) {
			if (workMinute < 15) {
				this.workMinuteName = "时间过短";
			} else if (workMinute > 60) {
				this.workMinuteName = "时间过长";
			} else {
				this.workMinuteName = "正常";
			}
		}
	}
}
